package cn.wawi.controller.sys;

import com.wawi.common.ResultData;
import com.wawi.common.annotation.MapperName;
import cn.wawi.controller.BaseController;
import cn.wawi.dao.sys.AppDao;
import com.wawi.utils.MybatisMap;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sys_app")
@MapperName(value="cn.wawi.dao.sys.AppDao")
public class AppController extends BaseController<MybatisMap<String,Object>>{
	
	/*@InitBinder({"department"})
	public void initBinder(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("department.");
	}*/
	@Resource
    private AppDao<MybatisMap<String,Object>> appDao;
	
	/**
	 *主页
	 */
	@RequestMapping(value="/main",method=RequestMethod.GET)
	public String main() {
		return "sys/App/main";
	}
	
	/**
	 * app检测更新
	 */
	@ResponseBody
	@RequestMapping(value="/checkUpdate",method={RequestMethod.POST,RequestMethod.GET})
	public ResultData<MybatisMap<String, Object>> checkAppUpdate() {
		ResultData<MybatisMap<String, Object>> result=new ResultData<MybatisMap<String, Object>>();
		MybatisMap<String, Object> app = appDao.findApp(paramaterMap);
		String appVersion=paramaterMap.get("versionName")==null?"":paramaterMap.get("versionName").toString();
		String serverVersion=app.get("versionName")==null?"":app.get("versionName").toString();
		if(serverVersion.compareTo(appVersion)>0){
			result.setRows(app);
		}else{
			result.setResCode("1");
			result.setResMsg("app暂无更新!");
		}
		return result;
	}
}
